<?php
namespace app\index\controller;
use app\common\model\Upload as UploadModel;

use app\common\controller\HomeBase;
class Upload extends HomeBase
{
    function _initialize()
    {
    	
        parent::_initialize();
        $this->model =new UploadModel();
    }
    public function upimage()
    {
        if (!session('userid')) {
            return "error|没有登录";
        }
    	 return json($this->model->upfile('images'));
    }
    public function upfile2()
    {
        if (!session('admin_id')) {
            return "error|没有登录";
        }
        return json($this->model->upfile('files'));
    }
    public function upfile()
    {
        if (!session('userid')) {
            return "error|没有登录";
        }
        $code=0;
        $data=[];
        $res=$this->model->upfile('files','file_name');
        if($res['code']==0){
            $code=1;
            $data['ext']=$res['data']['ext'];
            $data['src']=$res['data']['src'];
        }

        return json([
            'code'=>$code,
            'msg'=>$res['msg'],
            'data'=>$data
        ]);
    }

    public function wangeditor_upimage()
    {
        if (!session('userid')) {
            return "error|没有登录";
        } else {
            $info = $this->model->upfile("images", "FileName");
            return $info['data']['src'];
        }
    }
}